<?php 
namespace app\home\controller;
use think\Controller;
use think\Db;	
use think\Session;
use think\request;

//设置密码
class Editlogpwd extends Base{
	public function index(){
		return $this->fetch('Editlogpwd/index');
	}

    public function editPwd(){
	    $param = myarr($this->request->post());

        $pwd = $param['pwd'];
        $pwds = $param['pwds'];
        $logpwd = $param['logpwd'];
        $user = $this->userInformation();
        if(preg_match('/^[0-9a-zA-Z]+$/',$pwd) != 1){
            $this->error('密码格式错误','Editlogpwd/index');
        }
        if(preg_match('/^[0-9a-zA-Z]+$/',$pwds) != 1){
            $this->error('密码格式错误','Editlogpwd/index');
        }
        if(count($pwd) < 6 && count($pwd) > 15 ){
            $this->error('密码格式错误','Editlogpwd/index');
        }
        if($pwd!=$pwds){
            $this->error('密码不一致','Editlogpwd/index');
        }

        if($user['password']!=$logpwd){
            $this->error('原密码校验失败','Editlogpwd/index');
        }

        if($pwd==$pwds){
            $user=Db::name('users')->where(['id'=>$user['id']])->update(['password' => $pwd]);
            if($user){
                session(null);
                $this->success('修改登录密码成功，请重新登录','/index/Login/index');
            }else{
                $this->error('修改失败','/index/Login/index');
            }
        }
    }



}